<template>
  <div class="demo">
    <el-card>
      <el-form inline label-width="100">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="api">
              <el-input v-model="apiurl" style="width: 400px;"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="params">
              <el-input v-model="paramsText" style="width: 400px;"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card style="margin-top: 10px;">
      <PageConditionForm   
        :default="defaultData" 
        :api="apiurl"  
        :params="apiParams" 
        label-width="85"
        @result="onPageFormChange" 
        @loaded="onChildLoaded"  
      />
      <div style="margin-top: 20px;">校验结果：{{ pageResult?.valid }}</div>
      <div style="margin-top: 20px;">输出JSON：{{ pageResult?.data }}</div>
    </el-card>
  </div>
</template>

<script>
import PageConditionForm from '@/components/PageConditionForm/index.vue'

export default {
  name: 'Demo',
  components: {
    PageConditionForm
  },
  data() {
    return {
      showBuilder: false,
      defaultData: [],
      defaultData: [ { "field_label": "通知通道", "field_key": "tongzhitongdao", "field_component": "select", "field_value_type": "string", "supported_operator": "auto", "is_require": "yes", "more_condition": [], "value": "auto" } ]  ,
      apiurl: 'https://z.bajie.io/dex/api/get_alert_field',
      paramsText: '{"size": "big","color": "red"}',
      pageResult: null
    }
  },
  computed: {
    apiParams() {
      try {
        return JSON.parse(this.paramsText)
      } catch (e) {
        return {}
      }
    }
  },
  mounted() {
    this.$emit('loaded')
  },

  methods: {
    onPageFormChange(result) {
      console.log(result)
      this.pageResult = result
    },
    onChildLoaded () {

    }
  }
}
</script>

<style lang="scss" scoped>
  .demo {
    margin: 0;
    color: #666;
  }
</style>